<?php

/**
 * Description of Task_ItemProvider
 *
 * @author prometheus
 */
class Task_ItemProvider extends x10_Provider
{
	public $xName = 'Taszklista elem szolgáltató';

	/**
	 * @var x10_Observer
	 */
	protected $item;

	protected $itemName = '';

	protected $itemClass = '';

	protected $arguments = array();

	/**
	 * @var Task
	 */
	public $parentTask;

	public function __construct(x10_Config $config=NULL)
	{
		parent::__construct($config);
		$this->itemName = $this->config->getConfigKey('itemName');
		$this->itemClass = $this->config->getConfigKey('itemClass');
		$item = $this->config->getConfigKey('item');
		$this->parentTask = $this->config->getConfigKey('parentTask');
		$this->parameters = $this->config->getConfigKey('parameters');
		if (!is_array($this->parameters)) $this->parameters = array();
		$this->arguments = $this->config->getConfigKey('arguments');
		if (!is_array($this->arguments)) $this->arguments = array();

		if (!is_null($this->itemClass) and !empty($this->itemClass))
		{
			$item = new $this->itemClass();
			$item->setParent($this->parentTask);
			$item->setProvider($this);
		}

		$this->item = new x10_Observer(
			new x10_Config(
				array(
					'object'	=> $item
				)
			)
		);

		$this->item[] = new x10_Observer_MethodProvider(
			new x10_Config(
				array(
					'methodName'	=> 'action',
					'callback'		=> array($this, 'onBeforeAction'),
					'onBefore'		=> TRUE
				)
			)
		);
		$this->item[] = new x10_Observer_MethodProvider(
			new x10_Config(
				array(
					'methodName'	=> 'action',
					'callback'		=> array($this, 'onAfterAction'),
					'onAfter'		=> TRUE
				)
			)
		);
	}

	public function get()
	{
		return $this->item;
	}

	public function call()
	{
		return call_user_func_array(array($this->item, 'action'), $this->parameters);
	}

	/**
	 * @return Task
	 */
	public function getParentTask()
	{
		return $this->parentTask;
	}

	public function onBeforeAction()
	{

	}

	public function onAfterAction()
	{
		
	}
}

?>